package com.szqhyxj.youxiangju.biz.partnerHome.shop;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.merchantHome.bean.PosCommodity;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.ShopFragment;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.adapter.CommoditeDeviceAdapter;
import com.szqhyxj.youxiangju.biz.merchantHome.shop.commoditeDetails.CommoditeDeviceDetailsActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by leung on 2018/10/31.
 */

public class PartnerShopFragment extends BasePromptFragment implements PartnerShopContract.View, CommoditeDeviceAdapter.OnItemClickListener{

    @BindView(R.id.creaditDetails)
    ListView creaditDetails;
    Unbinder unbinder;

    private CommoditeDeviceAdapter adapter;

    public static ShopFragment newInstance(){
        Bundle args = new Bundle();
        ShopFragment fragment = new ShopFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        PartnerShopPresenter shopPresenter = new PartnerShopPresenter(this);
        shopPresenter.init();
    }

    @Override
    protected int getLayoutId(){
        return R.layout.fragment_shop;
    }

    @Override
    public void showProductList(List<PosCommodity> data){
        adapter = new CommoditeDeviceAdapter(getContext(), data);
        adapter.setListener(PartnerShopFragment.this);
        creaditDetails.setAdapter(adapter);
    }

    @Override
    public void showToast(String s) {
        Toast.makeText(getActivity(),s,Toast.LENGTH_LONG).show();
    }

    @Override
    protected void start(){
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onClick(String packageId){
        CommoditeDeviceDetailsActivity.start(getActivity(),packageId);
    }

}